package com.example.demo.entity;

import com.timing.finder.framework.CacheData;
import com.timing.finder.framework.TimeSeriesData;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;

/**
 * 测试数据实体，实现TimeSeriesData接口表名该类是一个时序数据
 *
 * @author JingGe(* ^ ▽ ^ *)
 * @date 2023-07-17 15:11
 * @email 1158055613@qq.com
 */
@Getter
@Setter
public class TimingDataEntity implements TimeSeriesData {
    private Long id;
    private String data1;
    private Integer data2;
    private String selectKey1;
    private String selectKey2;
    private Date createTime;

    @Override
    public long id() {
        return id;
    }

    @Override
    public long timestamp() {
        if (createTime == null) {
            return -1;
        }
        return createTime.getTime();
    }

    @Override
    public String key() {
        //返回该时序数据的查询key，该key会作为缓存的key
        return selectKey1 + "_" + selectKey2;
    }

    @Override
    public CacheData storeValue() {
        //返回该实体要存到Redis中的数据
        return new TimingDataEntityCacheData(data1, data2, createTime);
    }
}
